/**
*文件用途说明：XpopDialog 弹窗
*依赖库：jQuery 1.4.4
*作者：徐国南
*制作日期： 2013-9-5
*修改日期： 
			2013-6-28 
					++++++++++++++++++++++++++++++++++++++++++++++++++++++
					遗留问题，待 优化 列表渲染部分
					++++++++++++++++++++++++++++++++++++++++++++++++++++++
**/


function ED(){
	console.log("new ED");
}
ED.prototype = {
	status : false,
	root : ".J-select-wuliu",
	wuliuContents : '<div class="J-select-wuliu select-wuliu">' +
				'<div class="select-wuliu-hd">' +
					'<a href="#">请选择</a>' +
				'</div>' +
				'<div class="select-wuliu-bd"></div>'+
			'</div>',
	popDialog : function(){
		return $.XpopDialog({
			id:"mypop",
			width:800,
			title:"发货准备",
			mask:true,
			closeable:true
			//fixed:true
		})
	},
	tab : function (){
		return $.Xtab({
			rootElement:".J-Xtab",
			tabHd:".Xtab_hd",
			tabBd:".Xtab_bd",
			tabItem:".Xtab_item"
		});
	},
	get_EDlist : function (){
		return $('<div class="J-wuliu-list wuliu-list">' +
			'<div class="J-Xtab Xtab">' +
				'<ul class="Xtab_hd">' +
					'<li class="on"><a href="#">A</a></li>' +
					'<li><a href="#">B</a></li>' +
					'<li><a href="#">D</a></li>' +
					'<li><a href="#">E</a></li>' +
					'<li><a href="#">G</a></li>' +
					'<li><a href="#">H</a></li>' +
					'<li><a href="#">J</a></li>' +
					'<li><a href="#">K</a></li>' +
					'<li><a href="#">L</a></li>' +
					'<li><a href="#">N</a></li>' +
					'<li><a href="#">Q</a></li>' +
					'<li><a href="#">S</a></li>' +
					'<li><a href="#">T</a></li>' +
					'<li><a href="#">X</a></li>' +
					'<li><a href="#">Y</a></li>' +
					'<li><a href="#">Z</a></li>' +
				'</ul>' +
				'<ul class="Xtab_bd">' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">安信达</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">邦送物流</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">DHL快递</a><a href="javascript:void(0);" class="mr10">大田物流</a><a href="javascript:void(0);" class="mr10">德邦物流</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">E邮宝</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">国通快递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">汇通快递</a><a href="javascript:void(0);" class="mr10">华宇物流</a><a href="javascript:void(0);" class="mr10">汇强快递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">佳吉快运</a><a href="javascript:void(0);" class="mr10">佳怡物流</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">快捷速递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">龙邦速递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">能达速递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">全一快递</a><a href="javascript:void(0);" class="mr10">全峰快递</a><a href="javascript:void(0);" class="mr10">全日通</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">申通快递</a><a href="javascript:void(0);" class="mr10">顺丰快递</a><a href="javascript:void(0);" class="mr10">速尔快递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">天天快递</a><a href="javascript:void(0);" class="mr10">天地华宇</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">新邦物流</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">圆通快递</a><a href="javascript:void(0);" class="mr10">韵达快递</a><a href="javascript:void(0);" class="mr10">优速快递</a></li>' +
					'<li class="Xtab_item"><a href="javascript:void(0);" class="mr10">中通快递</a><a href="javascript:void(0);" class="mr10">宅急送</a><a href="javascript:void(0);" class="mr10">中邮物流</a></li>' +
				'</ul>' +
			'</div>' +
		'</div>')
	},


	//public 显示
	showWuliu:function(){
		var self=this;
		$('body').append(self.get_EDlist());
		this.showWuliu = function(){
			//return this.showWuliu();
		}; 
		//return this.showPop(e);
		return this.showWuliu();
	},

	init:function(){
		var self=this;
		var EDlist = self.get_EDlist();
		var pop = self.popDialog();

		pop.setContent(self.wuliuContents);

		$('.J-pop').live('click',function(e){
			pop.showPop(e);
		   
		   self.showWuliu();
		   self.tab();
		});

		var root = $(self.root);

		root.delegate('.select-wuliu-hd', 'click',function(e){
			$(this).next(".select-wuliu-bd").append(EDlist);
			root.trigger("change.wuliu");
		});

		root.bind("change.wuliu",function(){
			if(self.status === false){
				self.status = true;
				root.addClass("on");
			}else{
				self.status = false;
				root.removeClass("on");
			}
		});

		root.delegate('.Xtab_item a','click',function(){
			console.log(root.children(".select-wuliu-hd"))
			root.children(".select-wuliu-hd").find('a').text($(this).text());
		});
	}
};


$(function(){
	var ed = new ED();
	ed.init();
});